package com.android.htdvideoview;

import android.app.Activity;
import android.content.res.Resources;
import android.os.Build;
import android.util.Log;
import android.view.View;
import android.view.ViewParent;

/**
 * 项目名称：VideoTest
 * 类 名 称：Utils
 * 类 描 述：TODO
 * 创建时间：2019-11-17 02:35
 * 创 建 人：sansecy
 */
public class Utils {

    public static View findContentView(View view) {
        View targetView = null;
        Resources r = view.getResources();
        while ((view = (View) view.getParent()) instanceof View) {
            targetView = view;
            if (r.getResourceEntryName(view.getId()).equals("content")) {
                break;
            }
        }
        return targetView;
    }

    public static View findDecorContentParent(View view) {
        View targetView = null;
        Resources r = view.getResources();
        while ((view = (View) view.getParent()) instanceof View) {
            targetView = view;
            if (r.getResourceEntryName(view.getId()).equals("decor_content_parent")) {
                break;
            }
        }
        return targetView;
    }

    private static final String TAG = "Utils-App";
    public static View findDecorView(View view) {
        View targetView = view;
        ViewParent parent;
        while ((parent = targetView.getParent()) instanceof View) {
            targetView = (View) parent;
            Log.d(TAG, "findDecorView: " + parent);
        }
        return targetView;
    }


    public static void hideStatusBar(Activity activity) {
        if (Build.VERSION.SDK_INT >= 19) {
            View decorView = activity.getWindow().getDecorView();
            decorView.setSystemUiVisibility(
                    View.SYSTEM_UI_FLAG_LAYOUT_STABLE
                            | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
                            | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                            | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
                            | View.SYSTEM_UI_FLAG_FULLSCREEN
                            | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);
        }
    }

    public static void showStatusBar(Activity activity) {
        if (Build.VERSION.SDK_INT >= 19) {
            View decorView = activity.getWindow().getDecorView();
            decorView.setSystemUiVisibility(
                    View.SYSTEM_UI_FLAG_LAYOUT_STABLE
                            | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                            | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
            );
        }
    }

}
